package cn.haona.game.simb.servlet;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;

import cn.haona.game.simb.object.god.MainManager;
import cn.haona.game.simb.object.god.cache.Cache;
import cn.haona.game.simb.wap.servlet.WebDefine;

public class SessionHnManager {

	/**
	 * 保存sessonHn
	 * 
	 * @param session
	 * @return
	 */
	public static boolean saveSessionHn(SessionHn session) {
		if (session.getId() != null) {
			Cache remoteCache = MainManager.getInstance().getCacheManager()
					.getRemoteCache();
			Date dateExpired = new Date(System.currentTimeMillis()
					+ WebDefine.SESSION_EXPIRED_TIME);
			remoteCache.set(session.getId(), session, dateExpired);
			return true;
		} else {
			return false;
		}
	}
	
	/**
	 * 得到SessionHn
	 * @return
	 */
	public static SessionHn getSessionHn()
	{
		// 得到ServletRequest;
		HttpServletRequest request = (HttpServletRequest) ActionContext
				.getContext().get(ServletActionContext.HTTP_REQUEST);

		// SessionHn
		SessionHn session = (SessionHn) request.getAttribute(Define.SESSION_ID);
		
		return session;
	}

}
